Page({
    data: {
        loginFormOpacity: 1, // 登录表单的透明度，初始状态下为1（完全不透明）
        registerFormOpacity: 0, // 注册表单的透明度，初始状态下为0（完全透明）
        isLoginFormVisible: true, // 是否显示登录表单
        isRegisterFormVisible: false, // 是否显示注册表单
        animationData1: {},
      animationData2: {},
      animationData3: {},
      animationData4: {},
      animationData5: {},

      account: null,
  username: null,
  newPassword: null,
  nickname1:'',
  password1:'',
  nickname2:'',
  password2:'',
  account:'',
      },

      'nickname1'(e){
        this.data.nickname1 = e.detail.value
      },
      'password1'(e){
        this.data.password1 = e.detail.value
      },
      'nickname2'(e){
        this.data.nickname2 = e.detail.value
      },
      'password2'(e){
        this.data.password2 = e.detail.value
      },


             // 注册按钮的点击事件处理函数
     Register: function() {
        console.log(this.data.nickname2);
        console.log(this.data.password2);
    
    // 发起网络请求
    wx.request({
      url: 'http://47.95.223.130:8083/User/signup', 
      
      data: {
        nickname: this.data.nickname2,
        password: this.data.password2,
      },
      method: 'POST',
      
      success: (res) => {
          console.log(res)
          console.log(this.data.nickname2)
          console.log(this.data.password2)
        // 请求成功，处理响应数据
        if (res.data.code === 200) { // 确保服务器的响应数据中包含一个code字段来表示请求是否成功
          this.setData({
            account: res.data.data.uuid, // 假设账号数据在响应的account字段中
          });
          // 显示注册成功的提示
          wx.showModal({
            title: '成功',
            content: '注册成功，您的账号为：' + this.data.account,
          })
        } else {
          // 处理注册失败的情况
          wx.showModal({
            title: '错误',
            content: res.data.message,
          })
        }
      },
      fail: (err) => {
        // 处理网络请求失败的情况
        wx.showModal({
          title: '错误',
          content: '网络请求失败',
        })
      },
    });
  },



      


      LoginIn2: function(e) {
        console.log(this.data.nickname1);
        console.log(this.data.password1);

        // 检查昵称和密码是否为空
    if(this.data.nickname1.trim() === "") {
        wx.showModal({
          title: '错误',
          content: '请输入昵称',
        })
        return; //提前终止，不继续进行下面的代码
      } 
    if (this.data.password1.trim() === "") {
        wx.showModal({
          title: '错误',
          content: '请输入密码',
        })
        return;
    }

        wx.request({
          url: 'http://47.95.223.130:8083/User/login',
          data: {
            nickname: this.data.nickname1,
            password: this.data.password1,
          },
          method: "POST",
          success: (res) => {
            console.log(res);
            console.log(this.data.nickname1)
            console.log(this.data.password1)
            if (res.data.code == 200 ) {
              wx.showToast({
                title: '登录成功',
              })
              
              wx.setStorageSync('userInfo', res.data.data);
              console.log(res.data.data)
              this.setData({
               
              }),
              
              setTimeout(
                function(){ //注意function这里不能缺少
                  wx.switchTab({
                    url: '/pages/index/index',
                  })
                },1000)
              
            } else {
                wx.showToast({
                    icon: 'error',
                    title: '账号或密码错误',
                  })
                  console.log(this.data.nickname1);
                  console.log(this.data.password1);
            }
            
          },
          //fail: (err) => {},
          //complete: (res) => {},
        })
      },


      changePassword: function() {
        
      },





    
      toggleForm() {
        if (this.data.isLoginFormVisible) {
          // 当前为登录表单显示状态，切换至注册表单显示状态
          this.setData(
            {
              loginFormOpacity: 0,
            },
            () => {
              // 等待登录表单透明度过渡完成后，再显示注册表单
              setTimeout(() => {
                this.setData({
                  isLoginFormVisible: false,
                  isRegisterFormVisible: true,
                  registerFormOpacity: 1,
                });
              }, 1000);
            }
          );
        } else {
          // 当前为注册表单显示状态，切换至登录表单显示状态
          this.setData(
            {
              registerFormOpacity: 0,
            },
            () => {
              // 等待注册表单透明度过渡完成后，再显示登录表单
              setTimeout(() => {
                this.setData({
                  isLoginFormVisible: true,
                  isRegisterFormVisible: false,
                  loginFormOpacity: 1,
                });
              }, 1000);
            }
          );
        }
      },

  
    onReady: function (){
      this.bounceAnimation('animationData1', 1950);
      this.bounceAnimation('animationData2', 1750);
      this.bounceAnimation('animationData3', 1650);
      this.bounceAnimation('animationData4', 1800);
      this.bounceAnimation('animationData5', 1950);
    },
  
    bounceAnimation: function(animationName, duration) {
      const animation = wx.createAnimation({
        duration: duration,
        timingFunction: 'linear',
        delay: 0,
        transformOrigin: '50% 50%',
      });
  
      animation.translateY(10).step().translateY(-10).step();
  
      let animation_data = {};
      animation_data[animationName] = animation.export();
      this.setData(animation_data);
  
      setInterval(() => {
        animation.translateY(10).step().translateY(-10).step();
        animation_data[animationName] = animation.export();
        this.setData(animation_data);
      }, duration * 2);
    },
  });
  